package com.event.listener.publish;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * @author shengtao
 * @Description:
 * @date 2019/06/27 15:42
 */
@Component
public class RefreashApplicationPublisher implements ApplicationEventPublisherAware{

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public <T extends ApplicationEvent> boolean publishEvent(T obj){
        try {
            this.applicationEventPublisher.publishEvent(obj);
        }catch (Exception e){
            return false;
        }
        return true;
    }

}
